patches-own [landuse available?]
globals [toy-available thistoy random-energy portion-passer-photo portion-walk-wander portion-exercise-rest portion-toy-photo worker-radius world-second
  num-agents
  num-use-toy num-use-photo num-use-exercise num-use-rest num-use-dinner;用于统计各种场地使用频次
  list-children-toy list-children-social list-children-photo ;用于统计各种行为人数
  list-adults-toy list-adults-social list-adults-photo list-adults-exercise list-adults-rest
  list-elders-social list-elders-rest list-elders-exercise
  list-workers-social list-workers-rest list-workers-exercise list-workers-dinner list-workers-photo
  list-time-children list-time-adults list-time-elders list-time-workers ;每个个体在场地上的时间
  list-time-children-toy list-time-children-social list-time-children-photo list-satisfaction-children ;用于统计各种人群的各种行为时间
  list-time-adults-toy list-time-adults-social list-time-adults-photo list-time-adults-exercise list-time-adults-rest list-satisfaction-adults
  list-time-elders-social list-time-elders-rest list-time-elders-exercise list-satisfaction-elders
  list-time-workers-social list-time-workers-rest list-time-workers-exercise list-time-workers-dinner list-time-workers-photo list-satisfaction-workers
  list-photo list-exercise list-rest list-dinner list-social list-toy ;统计各类活动的人数
  ;list-time-toy list-time-exercise list-time-rest list-time-photo list-time-dinner list-time-social ;统计各类活动时间
  ;num-social-workers num-social-photo num-social-toy num-social-exercise
  list-patchxy-toy list-patchxy-exercise list-patchxy-rest list-patchxy-photo list-patchxy-dinner list-patchxy-social ;统计各类用地位置
]
breed [children child ]
breed [adults adult ]
breed [elders elder ]
breed [workers worker]
children-own [velocity status energy energy-this social history my-time my-time-exercise my-time-toy my-time-social my-time-rest my-time-photo my-time-dinner satisfaction]
adults-own [velocity status energy energy-this social history my-time my-time-exercise my-time-toy my-time-social my-time-rest my-time-photo my-time-dinner satisfaction]
elders-own [velocity status energy energy-this social history my-time my-time-exercise my-time-toy my-time-social my-time-rest my-time-photo my-time-dinner satisfaction]
workers-own [velocity status energy energy-this social history my-time my-time-exercise my-time-toy my-time-social my-time-rest my-time-photo my-time-dinner satisfaction]
to setup
  clear-all
  ;set-current-directory "C:\\Users\\dorot\\Desktop\\mas模型\\mas_xiaowei"
  ;import-pcolors "200305s.jpg"
  ifelse playground = "current" ;按照现状或规划设置场地
  [set-pcolor-current
  set portion-photo-children 0
  set portion-photo-adults 0
  set portion-photo-workers 0
  ]
  [set-pcolor-future]
  setup-patches
  create-my-children num-children ;儿童初始化
  create-my-adults num-adults ;成人初始化
  create-my-elders num-elders ;老人初始化f
  create-my-workers num-workers ;工人初始化
  initial-nums
   set-parameters -1
  reset-ticks
end
to initial-nums
  set world-second 0 ;从0秒开始
  set random-energy 5 ;初始化能量时，每个人浮动的能量
  set portion-passer-photo 10;路过的人来拍照的比例
  set portion-walk-wander 10;目的地都被占，有同类在玩，正常状态不去社交，而去随机走动的比例
  set portion-exercise-rest 50;锻炼完之后，随机去休息的比例
  set portion-toy-photo 10;玩具完之后，随机去打卡的比例
  set worker-radius 1;工人们产生连接的距离
  set num-agents 0 ;总共产生的人数
  set num-use-toy 0
  set num-use-photo 0
  set num-use-exercise 0
  set num-use-rest 0
  set num-use-dinner 0
  set list-children-toy []
  set list-children-social []
  set list-children-photo []
  set list-adults-toy []
  set list-adults-social []
  set list-adults-photo []
 set list-adults-exercise []
 set list-adults-rest []
 set list-elders-social []
  set list-elders-rest []
  set list-elders-exercise []
 set list-workers-social []
 set list-workers-rest []
 set list-workers-exercise []
  set list-workers-dinner []
  set list-workers-photo []
 ; set num-social-photo 0
;  set num-social-toy 0
 ; set num-social-exercise 0
 ; set num-social-workers 0
  set list-photo []
  set list-exercise[]
  set list-rest[]
  set list-dinner[]
  set list-social[]
  set list-toy[]
   set list-time-workers [] ;每个个体在场地上的时间
  set list-time-children []
  set list-time-adults []
  set list-time-elders []
  set list-time-children-toy []
  set list-time-children-social []
  set list-time-children-photo []
  set list-time-adults-toy []
  set list-time-adults-social []
  set list-time-adults-photo []
  set list-time-adults-exercise []
  set list-time-adults-rest []
  set list-time-elders-social []
  set list-time-elders-exercise []
  set list-time-elders-rest []
  set list-time-workers-rest []
  set list-time-workers-social []
  set list-time-workers-photo []
  set list-time-workers-exercise []
  set list-time-workers-dinner []
  set list-satisfaction-children []
  set list-satisfaction-adults []
  set list-satisfaction-elders []
  set list-satisfaction-workers []
end

to set-pcolor-current
    ask patches [set pcolor black]
  ;背景
  ask patches with [pycor = 8 and pxcor >= -11 and pxcor <= 4] [set pcolor white]
  ask patches with [pycor = 7 and pxcor >= -12 and pxcor <= 11] [set pcolor white]
  ask patches with [pycor = 6 and pxcor >= -13 and pxcor <= 12] [set pcolor white]
  ask patches with [(pycor = 5 or pycor = 4) and pxcor >= -14 and pxcor <= 12] [set pcolor white]
  ask patches with [(pycor >= -1 and pycor <= 3) and pxcor >= -14 and pxcor <= 13] [set pcolor white]
  ask patches with [ pycor = -2 and pxcor >= -14 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -3 and pxcor >= 6 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -4 and pxcor >= 8 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -5 and pxcor >= 10 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -6 and pxcor >= 12 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -7 and pxcor = 14] [set pcolor white]
  ;休息
  ask patches with [ pycor = 8 and pxcor >= -11 and pxcor <= 4] [set pcolor cyan]
  ;ask patches with [ pycor = 7 and pxcor >= 5 and pxcor <= 11] [set pcolor cyan]
  ;ask patches with [ pxcor = 12 and pycor >= 4 and pycor <= 6] [set pcolor cyan]
  ;ask patches with [ pxcor = 13 and pycor >= 2 and pycor <= 3] [set pcolor cyan]
  ;toy [-3 6]
  ask patch 0 0 [ask patch -3 6 [set pcolor red]] ;
  ;健身设施
  ask patch 0 0 [ask patch -11 2 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch -4 2 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch -2 2 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 0 2 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 2 2 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 4 2 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 6 2 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 8 2 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 10 2 [set pcolor yellow]] ;
  ;桌椅
  ask patches with [ pycor >= 2 and pycor <= 3 and pxcor >= -8 and pxcor <= -7] [set pcolor magenta]
end


to set-pcolor-future
  ask patches [set pcolor black]
  ;背景
  ask patches with [pycor = 8 and pxcor >= -11 and pxcor <= 4] [set pcolor white]
  ask patches with [pycor = 7 and pxcor >= -12 and pxcor <= 11] [set pcolor white]
  ask patches with [pycor = 6 and pxcor >= -13 and pxcor <= 12] [set pcolor white]
  ask patches with [(pycor = 5 or pycor = 4) and pxcor >= -14 and pxcor <= 12] [set pcolor white]
  ask patches with [(pycor >= -1 and pycor <= 3) and pxcor >= -14 and pxcor <= 13] [set pcolor white]
  ask patches with [ pycor = -2 and pxcor >= -14 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -3 and pxcor >= 6 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -4 and pxcor >= 8 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -5 and pxcor >= 10 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -6 and pxcor >= 12 and pxcor <= 14] [set pcolor white]
  ask patches with [ pycor = -7 and pxcor = 14] [set pcolor white]
  ;桌椅
  ask patches with [ pycor >= 5 and pycor <= 6 and pxcor >= 4 and pxcor <= 5] [set pcolor magenta]
  ask patches with [ pycor >= 5 and pycor <= 6 and pxcor >= -3 and pxcor <= -2] [set pcolor magenta]
  ;打卡设施
  ask patch 0 0 [ask patch -11 5 [set pcolor blue]]


  ;toy [-11 3] [12 -1] [-6 5] [0 4] [-9 4] [-9 2]
  ask patch 0 0 [ask patch -11 3 [set pcolor red]] ;
  ask patch 0 0 [ask patch 11 -1 [set pcolor red]] ;
  ask patch 0 0 [ask patch -6 5 [set pcolor red]] ;
  ask patch 0 0 [ask patch 0 4 [set pcolor red]] ;
  ask patch 0 0 [ask patch -9 4 [set pcolor red]] ;
  ask patch 0 0 [ask patch -9 2 [set pcolor red]] ;

  ;游戏设施（围合型）
  ;ask patch 0 0 [ask patch -11 3 [set pcolor red]] ;
  ;ask patch 0 0 [ask patch -9 4 [set pcolor red]] ;
  ;ask patch 0 0 [ask patch -9 2 [set pcolor red]] ;
  ;ask patch 0 0 [ask patch -7 2 [set pcolor red]] ;
  ;ask patch 0 0 [ask patch -7 4 [set pcolor red]] ;
  ;ask patch 0 0 [ask patch -5 3 [set pcolor red]] ;



  ;健身设施
  ask patch 0 0 [ask patch 0 1 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch -4 1 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 4 1 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch -2 1 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 2 1 [set pcolor yellow]] ;
  ask patch 0 0 [ask patch 6 1 [set pcolor yellow]] ;
  ;休息
  ask patch 0 0 [ask patch -2 8 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -3 8 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -9 8 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -8 8 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -7 8 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -6 8 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -5 8 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -4 8 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 11 7 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 12 6 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 12 5 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 12 4 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 13 3 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 13 2 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 13 1 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 13 0 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 12 -6 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 13 -6 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 10 -5 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 11 -5 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 8 -4 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 9 -4 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 6 -3 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch 7 -3 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -11 -2 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -10 -2 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -8 -2 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -7 -2 [set pcolor cyan]] ;
  ask patch 0 0 [ask patch -6 -2 [set pcolor cyan]] ;
end

to setup-patches

  set list-patchxy-dinner []
  set list-patchxy-toy []
  set list-patchxy-exercise []
  set list-patchxy-rest []
  set list-patchxy-photo []
  ask patches with [pcolor = red] [;玩具
    set landuse "toy"
  set list-patchxy-toy lput list pxcor pycor list-patchxy-toy
  ]
  ask patches with [pcolor = red] [set available? true] ;玩具 空闲
  ask patches with [pcolor = blue] [set landuse "photo"
   set list-patchxy-photo lput  list pxcor pycor  list-patchxy-photo] ;拍照打卡
  ask patches with [pcolor = yellow] [set landuse "exercise"
   set list-patchxy-exercise lput  list pxcor pycor  list-patchxy-exercise] ;健身设施
  ask patches with [pcolor = cyan] [set landuse "rest"
   set list-patchxy-rest lput  list pxcor pycor  list-patchxy-rest] ;休息
  ask patches with [pcolor = magenta] [set landuse "dinner"
   set list-patchxy-dinner lput  list pxcor pycor list-patchxy-dinner] ;桌椅
end

to set-parameters [tks] ;设定每个小时的参数
if tks = -1 [
  ;设定第1个小时的参数
  set increase-children 28
  set portion-photo-children 0

  set increase-adults 64
  set portion-photo-adults 0
  set portion-pass-adults 36
  set portion-exercise-adults 6
  set portion-rest-adults 43

  set increase-elders 6
  set portion-exercise-elders 50

  set increase-workers 45
  set portion-rest-workers 62
  set portion-photo-workers 0
  set portion-exercise-workers 13
  ]

  if tks = 0  ;设定7点的参数
  [
  set increase-children 0
  set portion-photo-children 0

  set increase-adults 0
  set portion-photo-adults 0
  set portion-pass-adults 0
  set portion-exercise-adults 0
  set portion-rest-adults 0

  set increase-elders 3
  set portion-exercise-elders 100

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 3600  ;设定8点的参数
  [
  set increase-children 3
  set portion-photo-children 0

  set increase-adults 17
  set portion-photo-adults 0
  set portion-pass-adults 50
  set portion-exercise-adults 50
  set portion-rest-adults 0

  set increase-elders 23
  set portion-exercise-elders 100

  set increase-workers 6
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 7200  ;设定9点的参数
  [
  set increase-children 0
  set portion-photo-children 0

  set increase-adults 17
  set portion-photo-adults 0
  set portion-pass-adults 50
  set portion-exercise-adults 50
  set portion-rest-adults 0

  set increase-elders 23
  set portion-exercise-elders 100

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 10800  ;设定10点的参数
  [
  set increase-children 8
  set portion-photo-children 0

  set increase-adults 25
  set portion-photo-adults 0
  set portion-pass-adults 67
  set portion-exercise-adults 22
  set portion-rest-adults 11

  set increase-elders 23
  set portion-exercise-elders 87

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 14400  ;设定11点的参数
  [
  set increase-children 11
  set portion-photo-children 0

  set increase-adults 14
  set portion-photo-adults 0
  set portion-pass-adults 40
  set portion-exercise-adults 40
  set portion-rest-adults 20

  set increase-elders 11
  set portion-exercise-elders 75

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 18000  ;设定12点的参数
  [
  set increase-children 28
  set portion-photo-children 0

  set increase-adults 147
  set portion-photo-adults 0
  set portion-pass-adults 35
  set portion-exercise-adults 6
  set portion-rest-adults 43

  set increase-elders 6
  set portion-exercise-elders 50

  set increase-workers 44
  set portion-rest-workers 62
  set portion-photo-workers 0
  set portion-exercise-workers 25
  ]


  if tks = 21600  ;设定13点的参数
  [
  set increase-children 0
  set portion-photo-children 0

  set increase-adults 64
  set portion-photo-adults 0
  set portion-pass-adults 82
  set portion-exercise-adults 5

  set increase-elders 6
  set portion-exercise-elders 50

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 25200  ;设定14点的参数
  [
  set increase-children 9
  set portion-photo-children 0

  set increase-adults 22
  set portion-photo-adults 0
  set portion-pass-adults 50
  set portion-exercise-adults 25
  set portion-rest-adults 25

  set increase-elders 11
  set portion-exercise-elders 100

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 28800 ;设定15点的参数
  [
  set increase-children 20
  set portion-photo-children 0

  set increase-adults 58
  set portion-photo-adults 0
  set portion-pass-adults 43
  set portion-exercise-adults 15
  set portion-rest-adults 28

  set increase-elders 3
  set portion-exercise-elders 100

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 32400 ;设定16点的参数
  [
  set increase-children 0
  set portion-photo-children 0

  set increase-adults 17
  set portion-photo-adults 0
  set portion-pass-adults 66
  set portion-exercise-adults 34
  set portion-rest-adults 0

  set increase-elders 3
  set portion-exercise-elders 100

  set increase-workers 3
  set portion-rest-workers 100
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]


  if tks = 36000 ;设定17点的参数
  [
  set increase-children 0
  set portion-photo-children 0

  set increase-adults 31
  set portion-photo-adults 0
  set portion-pass-adults 100
  set portion-exercise-adults 0
  set portion-rest-adults 0

  set increase-elders 0
  set portion-exercise-elders 0

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 39600 ;设定18点的参数
  [
  set increase-children 3
  set portion-photo-children 0

  set increase-adults 14
  set portion-photo-adults 0
  set portion-pass-adults 100
  set portion-exercise-adults 0
  set portion-rest-adults 0

  set increase-elders 9
  set portion-exercise-elders 100

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]

  if tks = 43200 ;设定19点的参数
  [
  set increase-children 0
  set portion-photo-children 0

  set increase-adults 14
  set portion-photo-adults 0
  set portion-pass-adults 60
  set portion-exercise-adults 20
  set portion-rest-adults 20

  set increase-elders 0
  set portion-exercise-elders 0

  set increase-workers 0
  set portion-rest-workers 0
  set portion-photo-workers 0
  set portion-exercise-workers 0
  ]
  if tks = 46800 [stop]
end

to go
  go-children
  go-adults
  go-elders
  go-workers
  set world-second world-second + 1
  set list-photo (sentence list-children-photo list-adults-photo)
  set list-exercise (sentence list-adults-exercise list-elders-exercise list-workers-exercise)
  set list-rest (sentence list-adults-rest list-workers-rest list-elders-rest)
  set list-dinner list-workers-dinner
  set list-social (sentence list-children-social list-adults-social list-elders-social list-workers-social)
  set list-toy (sentence list-children-toy list-adults-toy)
  to-file
  if preset [ ;是否采用预设的值
    set-parameters ticks]
  tick
end

to go-workers
  go-exercise workers
  go-rest workers
  go-photo workers
  go-dinner workers
  to-link workers ;工人们吃饭交谈
  to-home workers
  breed-us "workers"
  add-time workers
end

to go-elders
  go-exercise elders
  go-rest elders
  to-home elders
  breed-us "elders"
  add-time elders
end

to go-adults
  go-photo adults
  go-toy adults ;玩玩具、找玩具社交
  go-exercise adults
  go-rest adults
  to-home adults
  breed-us "adults"
  add-time adults
end

to go-children
  go-toy children ;玩玩具、找玩具社交
  go-photo children
  to-home children
  breed-us "children"
  add-time children
end

to create-my-workers [num] ;新增工人
  create-workers num [
    setxy random-xcor random-ycor
    set velocity [0 0 ] ;速度矢量
    ifelse random 100 < portion-exercise-adults [
   set status "walking-exercise" ] ;锻炼
    [ifelse random 100 - portion-exercise-adults < portion-photo-adults
      [set status "walking-photo"] ;拍照
      [ifelse random 100 - portion-exercise-adults - portion-photo-adults < portion-rest-adults
        [set status "walking-rest"];休息
        [set status "walking-dinner"];吃饭
      ]
    ]
    set size 1
    set shape "person"
    set color brown
    set social false
    set energy energy-workers + (random random-energy) - random-energy / 2
    set history []
    set my-time 0
    set my-time-exercise 0
    set my-time-toy 0
    set my-time-social 0
    set my-time-rest 0
    set my-time-photo 0
    set my-time-dinner 0
    set satisfaction 0
  ]
end

to create-my-elders [num] ;新增老人
  create-elders num [
    setxy random-xcor random-ycor
    set velocity [0 0 ] ;速度矢量
    ifelse random 100 < portion-exercise-adults [
   set status "walking-exercise" ] ;拍照
    [set status "walking-rest"]
    set size 1
    set shape "person"
    set color violet
    set social false
    set energy energy-elders + (random random-energy) - random-energy / 2
    set history []
    set my-time 0
    set my-time-exercise 0
    set my-time-toy 0
    set my-time-social 0
    set my-time-rest 0
    set my-time-photo 0
    set my-time-dinner 0
    set satisfaction 0
  ]
end

to create-my-adults [num] ;新增成人
  create-adults num [
    setxy random-xcor random-ycor
    set velocity [0 0 ] ;速度矢量
    ifelse random 100 < portion-photo-adults [
   set status "walking-photo" ] ;拍照
    [ifelse random (100 - portion-photo-adults ) < portion-pass-adults [
      ifelse random 100 < portion-passer-photo [set status "walking-photo" ] ;经过的人来拍照
      [set status "goinghome"]
      ][ ifelse random (100 - portion-photo-adults - portion-pass-adults) < portion-exercise-adults [set status "walking-exercise"] ; 健身
      [ ifelse  random (100 - portion-photo-adults - portion-pass-adults - portion-exercise-adults) < portion-rest-adults
        [set status "walking-rest"]
        [set status "walking"]];玩玩具
      ]
    ]
    set size 1
    set shape "person"
    set color orange
    set social false
    set energy energy-adults + (random random-energy) - random-energy / 2
    set history []
    set my-time 0
    set my-time-exercise 0
    set my-time-toy 0
    set my-time-social 0
    set my-time-rest 0
    set my-time-photo 0
    set my-time-dinner 0
    set satisfaction 0
  ]
end

to create-my-children [num] ;新增儿童
  create-children num [
    setxy random-xcor random-ycor
    set velocity [0 0 ] ;速度矢量
    ifelse random 100 >= portion-photo-children [
   set status "walking" ]
    [set status "walking-photo"]
    set size 1
    set shape "person"
    set color green
    set social false
    set energy energy-children + (random random-energy) - random-energy / 2
    set history []
    set my-time 0
    set my-time-exercise 0
    set my-time-toy 0
    set my-time-social 0
    set my-time-rest 0
    set my-time-photo 0
    set my-time-dinner 0
    set satisfaction 0
  ]
end

to go-rest [group]
  check-status "rest" group
  check-energy "rest" group
  to-toy "rest" group
end


to go-toy [group]
  check-status "toy" group ;children是否找到玩具或社交点
  check-energy "toy" group ;检查体力
  to-toy "toy" group ;玩耍或社交
  to-wander "toy" group

end

to go-photo [group]
  check-status "photo" group
  check-energy "photo" group ;检查体力
  to-toy "photo" group ;玩耍或社交
    to-wander "photo" group
end

to go-exercise [group]
  check-status "exercise" group ; 是否找到玩具或社交点
  check-energy "exercise" group ;检查体力
  to-toy "exercise" group ;玩耍或社交
  to-wander "exercise" group
end

to go-dinner [group]
  check-status "dinner" group ; 是否找到玩具或社交点
  check-energy "dinner" group ;检查体力
  to-toy "dinner" group ;玩耍或社交
  to-wander "dinner" group
end

to set-num-use [object]
  if object = "toy" [set num-use-toy num-use-toy + 1]
  if object = "rest" [set num-use-rest num-use-rest + 1]
  if object = "photo" [set num-use-photo num-use-photo + 1]
  if object = "exercise" [set num-use-exercise num-use-exercise + 1]
  if object = "dinner" [set num-use-dinner num-use-dinner + 1]
end

to set-list-play [object group]
  if group = children [
    if object = "toy" [if not member? who list-children-toy [set list-children-toy lput who list-children-toy ]]
   if object = "photo" [if not member? who list-children-photo [set list-children-photo lput who list-children-photo ]]
   ]
    if group = adults [
    if object = "toy" [if not member? who list-adults-toy [set list-adults-toy lput who list-adults-toy ]]
   if object = "photo" [if not member? who list-adults-photo [set list-adults-photo lput who list-adults-photo ]]
    if object = "exercise" [if not member? who list-adults-exercise [set list-adults-exercise lput who list-adults-exercise ]]
   if object = "rest" [if not member? who list-adults-rest [set list-adults-rest lput who list-adults-rest ]]
   ]
    if group = elders [
    if object = "exercise" [if not member? who list-elders-exercise [set list-elders-exercise lput who list-elders-exercise ]]
   if object = "rest" [if not member? who list-elders-rest [set list-elders-rest lput who list-elders-rest ]]
   ]
    if group = workers [
    if object = "dinner" [if not member? who list-workers-dinner [set list-workers-dinner lput who list-workers-dinner ]]
   if object = "photo" [if not member? who list-workers-photo [set list-workers-photo lput who list-workers-photo ]]
    if object = "exercise" [if not member? who list-workers-exercise [set list-workers-exercise lput who list-workers-exercise ]]
   if object = "rest" [if not member? who list-workers-rest [set list-workers-rest lput who list-workers-rest ]]
  ]
end


to set-list-social [object group]
  if group = children [
  if not member? self list-children-social [set list-children-social lput self list-children-social ]
   ]
  if group = adults [
  if not member? self list-adults-social [set list-adults-social lput self list-adults-social ]
   ]
  if group = elders [
  if not member? self list-elders-social [set list-elders-social lput self list-elders-social ]
  ]
end

to add-my-time [ object ]
  if object = "toy" [
  set my-time-toy my-time-toy + 1
  ]
  if object = "exercise" [
  set my-time-exercise my-time-exercise + 1
  ]
  if object = "rest" [
  set my-time-rest my-time-rest + 1
  ]
  if object = "photo" [
  set my-time-photo my-time-photo + 1
  ]
  if object = "dinner" [
  set my-time-dinner my-time-dinner + 1
  ]
end

;to set-num-social [object]
;  if object = "toy" [set num-social-toy num-social-toy + 1]
;  if object = "photo" [set num-social-photo num-social-photo + 1]
 ; if object = "exercise" [set num-social-exercise num-social-exercise + 1]
;end

to check-status [object group]
  let color-available red
  let color-occupied pink
  let status-walking "walking"
  let status-goingsocial "goingsocial"
  let status-socialing "socialing"
  let status-wandering "wandering"
  let status-playing "playing"
  let energy-us energy-children
  let energy-object energy-toy
  let list-land list-patchxy-toy

  if object = "photo" [
    set color-available blue
  set color-occupied sky
  set status-walking "walking-photo"
  set status-goingsocial "goingsocial-photo"
  set status-socialing "socialing-photo"
  set status-wandering "wandering-photo"
    set status-playing "playing-photo"
    set energy-object time-photo
  ]
  if object = "exercise" [
    set color-available yellow
  set color-occupied 44
  set status-walking "walking-exercise"
  set status-goingsocial "goingsocial-exercise"
  set status-socialing "socialing-exercise"
  set status-wandering "wandering-exercise"
    set status-playing "playing-exercise"
    set energy-object energy-exercise
  set list-land list-patchxy-exercise
  ]

  if object = "rest" [
    set color-available cyan
  set color-occupied 87
  set status-walking "walking-rest"
  set status-goingsocial "goingsocial-rest"
  set status-socialing "socialing-rest"
  set status-wandering "wandering-rest"
  set status-playing "playing-rest"
    set energy-object time-rest
  ]
  if object = "dinner" [
    set color-available magenta
  set color-occupied magenta + 2
  set status-walking "walking-dinner"
  set status-goingsocial "goingsocial-dinner"
  set status-socialing "socialing-dinner"
  set status-wandering "wandering-dinner"
  set status-playing "playing-dinner"
    set energy-object time-dinner
  ]

  if group = workers [
  set energy-us energy-workers
  ]
  if group = adults [
  set energy-us energy-adults
  ]
  if group = elders [
  set energy-us energy-elders
  ]

  ; 玩具、锻炼玩过所有就回家
  if object = "toy" or object = "exercise" [
    ask group with [status = status-walking][
      if list2contain1 list-land history [set status "goinghome"]
    ]
  ]
      ;如果有玩具空下来就初始化
    ifelse count patches with [pcolor = color-available] > 0 [
    ask group with [status = status-goingsocial or status = status-wandering] [
      let available-toy ( patches with [  pcolor = color-available and not member? list pxcor pycor [history] of myself ]) ;该玩具不能是上一次玩过的
      if count available-toy > 0  [set status status-walking]]
  ]
  [ ifelse object = "rest" [ ;休息行为没有社交，没有空场所就切换状态
      if group = elders [ ask group with [status = status-walking] [set status "walking-exercise"]]
      if group = adults or group = workers [ ask group with [status = status-walking] [ set status "goinghome"]    ]
    ][
    ;工人：锻炼、吃饭、拍照，如果没空场所就切换为rest
    ifelse group = workers and (object = "dinner" or object = "exercise" or object = "photo") [ ;休息行为没有社交，没有空场所就切换状态
       ask group with [status = status-walking] [set status "walking-rest"]
    ][
   let available-social-toy ( patches with [pcolor = color-occupied and any? turtles-here with [ breed = group and status = status-playing and social = false ]])
   ;玩具没有空余，且有本族群在使用玩具, 且不在社交中：找社交/随机行走; 或去随机行走
    ifelse count patches with [pcolor = color-available] = 0 and count available-social-toy > 0[
      ask group with [status = status-walking][
     ifelse random 100 >= portion-walk-wander [ ; 随机决定是否去找社交:90%概率
          set status status-goingsocial
        ][
          set status status-wandering
        ]
    ]
    ][;如果没有空余玩具、没有同组群在玩，设置为wander
      ask group with [status = status-walking or status = status-goingsocial  ][ set status status-wandering]
  ]]]]

  ask group with [status = status-walking]  [
    ifelse group = workers and (object = "dinner" or object = "rest")
     ;如果是工人找座位，倾向于在一起( TODO
    [
   ;   let prefer-seat ( patches with [
    ;    pcolor = color-available and any? neighbors with [pcolor = color-occupied and any? turtles-here with [ breed = group and status = status-playing ]]
    ;])
     ; ifelse count prefer-seat > 0 ;  有可以社交的座位
      ;[if pcolor = color-available and
    ;   ;   member? patch-here prefer-seat[
    ;  any? neighbors with [pcolor = color-occupied and any? turtles-here with [ breed = group and status = status-playing ]] [ ;到社交座位再坐下
     ; ask patch-here [set pcolor color-occupied]
     ; ask patch-here [set available? false]
     ; set status status-playing
     ; setxy pxcor pycor
     ; set energy-this random energy-object  ; 随机取在这里玩的能量
     ; if energy-this > energy [set energy-this energy]
     ; ]    ][;没有社交位置，到空位坐下
       if pcolor = color-available [
      ask patch-here [set pcolor color-occupied]
      ask patch-here [set available? false]
      set status status-playing
      setxy pxcor pycor
      set energy-this random-normal energy-object 600 ; 随机取在这里玩的能量
      if energy-this > energy [set energy-this energy]
        set-num-use object ;增加使用数量
        set-list-play object group ;加入使用列表
        ]
    ]
    ;如果不是工人
    [  ;该玩具不能是上一次玩过的
    if pcolor = color-available and (not member? list pxcor pycor [history] of self ) [
      ask patch-here [set pcolor color-occupied]
      ask patch-here [set available? false]
      set status status-playing
      setxy pxcor pycor
      set energy-this random-normal energy-object 600 ; 随机取在这里玩的能量
      if energy-this > energy [set energy-this energy]
        set-num-use object ;增加使用数量
        set-list-play object group ;加入使用列表
    ]]
   ]

  ask group with [status = status-goingsocial]  [
    ; 选离我最近的玩具，有族群在这儿，且没在社交
    let available-social-toy ( patches with [pcolor = color-occupied and any? turtles-here with [ breed = group and status = status-playing  and social = false]])
    if  count available-social-toy > 0 [
      let mytoy min-one-of available-social-toy [ dis [xcor] of myself [ycor] of myself pxcor  pycor ]
          if  dis xcor ycor [pxcor] of mytoy [pycor] of mytoy <= 1
           ;距离最近的粉色格子小于1
          [
            set status status-socialing
        set social true
             ;把它放在玩具旁边
            setxy [pxcor] of mytoy [pycor] of mytoy
            set heading random 361
            forward 1
            ;跟正在玩游戏的儿童社交 建立连接
            let attached ([turtles in-radius 4 ] of mytoy) with [ breed = group and status = status-playing and social = false]
            create-link-with one-of attached
        ask one-of attached [set social true]
            ask my-links [set color gray]
            set energy-this random-normal energy-object 600 ; 随机取社交能量
        if energy-this > energy [set energy-this energy]
      ;  set-num-social object;增加社交数量
        set-list-social object group ;加入社交列表
]
    ]
  ]

end

to check-energy-wander [group status-wandering]
  ask group with [status = status-wandering] [
    ifelse energy <= 0 [set status "goinghome"]
    [set energy energy - 1
    set satisfaction satisfaction - 1]
  ]
end

to set-energy-playing [object energy1 energy-this1 my-time-toy1 my-time-exercise1 my-time-rest1 my-time-photo1 my-time-dinner1 my-time-social1 satisfaction1]
 set energy-this1 energy-this1 - 1
      set energy1 energy1 - 1
          if object = "toy" [
  set my-time-toy1 my-time-toy1 + 1
  ]
  if object = "exercise" [
  set my-time-exercise1 my-time-exercise1 + 1
  ]
  if object = "rest" [
  set my-time-rest1 my-time-rest1 + 1
  ]
  if object = "photo" [
  set my-time-photo1 my-time-photo1 + 1
  ]
  if object = "dinner" [
  set my-time-dinner1 my-time-dinner1 + 1
  ]
  if object = "social" [
  set my-time-social1 my-time-social1 + 1
  ]
        set satisfaction1 satisfaction1 + 1 ;正在play，提高满意度
end

to check-energy [object group]
  let color-available red
  let color-occupied pink
  let status-walking "walking"
  let status-goingsocial "goingsocial"
  let status-socialing "socialing"
  let status-wandering "wandering"
  let status-playing "playing"
  let energy-us energy-children

  if object = "photo" [
    set color-available blue
  set color-occupied sky
  set status-walking "walking-photo"
  set status-goingsocial "goingsocial-photo"
  set status-socialing "socialing-photo"
  set status-wandering "wandering-photo"
    set status-playing "playing-photo"
    ]
  if object = "exercise" [
    set color-available yellow
  set color-occupied 44
  set status-walking "walking-exercise"
  set status-goingsocial "goingsocial-exercise"
  set status-socialing "socialing-exercise"
  set status-wandering "wandering-exercise"
    set status-playing "playing-exercise"
  ]
    if object = "rest" [
    set color-available cyan
  set color-occupied 87
  set status-walking "walking-rest"
  set status-goingsocial "goingsocial-rest"
  set status-socialing "socialing-rest"
  set status-wandering "wandering-rest"
  set status-playing "playing-rest"
  ]
  if object = "dinner" [
    set color-available magenta
  set color-occupied magenta + 2
  set status-walking "walking-dinner"
  set status-goingsocial "goingsocial-dinner"
  set status-socialing "socialing-dinner"
  set status-wandering "wandering-dinner"
  set status-playing "playing-dinner"
  ]

  if group = workers [
  set energy-us energy-workers
  ]
  if group = adults [
  set energy-us energy-adults
  ]
  if group = elders [
  set energy-us energy-elders
  ]
  if (object = "exercise" or object = "toy") and group != workers [ ;锻炼或玩具，做完之后, 如果还有能量的话继续
  ask group with [status = status-playing] [
    ifelse energy <= 0 or energy-this <= 0[
      ask patch-here [set pcolor color-available]
      ask patch-here [set available? true]
      ask link-neighbors [
          set status status-walking
        set social false]
      ask my-links [die]
        set social false
      ifelse energy <= 0 [
          if object = "exercise" [
            ifelse random 100 < portion-exercise-rest ;锻炼完后如果没有能量，随机去休息
          [set status "walking-rest"
          set energy time-rest] ;设置总能量为休息所需的能量
          [set status "goinghome"];否则回家
          ]
          if object = "toy" [
            ifelse random 100 < portion-toy-photo ;玩耍完后如果没有能量，随机去拍照
          [set status "walking-photo"
          set energy time-photo] ;设置总能量为拍照所需的能量
          [set status "goinghome"];否则回家
          ]
        ]
      [set status status-walking ;寻找下一个目标
          if not member?  [list pxcor pycor] of patch-here history ;并将玩过的放入历史
          [set history lput [list pxcor pycor] of patch-here history]]
    ] [
        set-energy-playing object energy energy-this my-time-toy my-time-exercise my-time-rest my-time-photo my-time-dinner my-time-social satisfaction
    ]
  ]
   ask group with [status = status-socialing ] [
    ifelse energy <= 0 or energy-this <= 0 [
       ;停止社交
      ask my-links [die]
        set social false
      ifelse energy > 0 [ set status status-walking ]   ;继续行走
      [  set status "goinghome"];否则回家
    ][
        set-energy-playing  "social" energy energy-this my-time-toy my-time-exercise my-time-rest my-time-photo my-time-dinner my-time-social satisfaction
    ]
  ]
    check-energy-wander  group status-wandering ;wander消耗能量
    ]
    if (object = "rest" or object = "photo") and group != workers [ ;休息\拍照 ，做完之后就回家
  ask group with [status = status-playing] [
    ifelse energy <= 0 or energy-this <= 0[
      ask patch-here [set pcolor color-available]
      ask patch-here [set available? true]
      ask link-neighbors [
          set status status-walking
        set social false]
      ask my-links [die]
       set status "goinghome"
        set social false
    ] [
       set-energy-playing object energy energy-this my-time-toy my-time-exercise my-time-rest my-time-photo my-time-dinner my-time-social satisfaction
    ]
  ]
   ask group with [status = status-socialing ] [
    ifelse energy <= 0 or energy-this <= 0 [
       ;停止社交
      ask my-links [die]
        set social false
       set status "goinghome"
    ][
   set-energy-playing  "social" energy energy-this my-time-toy my-time-exercise my-time-rest my-time-photo my-time-dinner my-time-social satisfaction
    ] ]
    check-energy-wander  group status-wandering ;wander消耗能量
  ]

  if  group = workers  [;工人所有活动，包含特殊社交，做完之后就回家
      ask group with [status = status-playing] [
    ifelse energy <= 0 or energy-this <= 0[
      ask patch-here [set pcolor color-available]
      ask patch-here [set available? true]
      ask my-links [die]
       set status "goinghome"
        set social false
    ] [
      set-energy-playing object energy energy-this my-time-toy my-time-exercise my-time-rest my-time-photo my-time-dinner my-time-social satisfaction
    ]
      if social = true [  set my-time-social my-time-social + 1]
    ]
    check-energy-wander  group status-wandering ;wander消耗能量
  ]

end


to to-toy [object group] ;找玩具并向玩具迈一步,找一个空闲toy, 速度、方向指向toy, 走路 。

  let color-available red
  let color-occupied pink
  let status-walking "walking"
  let status-goingsocial "goingsocial"
  let status-socialing "socialing"
  let status-wandering "wandering"
  let status-playing "playing"

  if object = "photo" [
    set color-available blue
  set color-occupied sky
  set status-walking "walking-photo"
  set status-goingsocial "goingsocial-photo"
  set status-socialing "socialing-photo"
  set status-wandering "wandering-photo"
    set status-playing "playing-photo"
    ]
  if object = "exercise" [
    set color-available yellow
  set color-occupied 44
  set status-walking "walking-exercise"
  set status-goingsocial "goingsocial-exercise"
  set status-socialing "socialing-exercise"
  set status-wandering "wandering-exercise"
    set status-playing "playing-exercise"
  ]
      if object = "rest" [
    set color-available cyan
  set color-occupied 87
  set status-walking "walking-rest"
  set status-goingsocial "goingsocial-rest"
  set status-socialing "socialing-rest"
  set status-wandering "wandering-rest"
  set status-playing "playing-rest"
  ]
  if object = "dinner" [
    set color-available magenta
  set color-occupied magenta + 2
  set status-walking "walking-dinner"
  set status-goingsocial "goingsocial-dinner"
  set status-socialing "socialing-dinner"
  set status-wandering "wandering-dinner"
  set status-playing "playing-dinner"

  ]
  ask group with [status = status-walking] [ ;  状态 游荡的
    let available-toy ( patches with [
     pcolor = color-available and not member? list pxcor pycor [history] of myself
    ]) ;该玩具不能是上一次玩过的
    ifelse group = "workers" ;and object = "rest"
    ;如果是工人找休息的座位，倾向于在一起
    [;邻座是有同组群正在play的
      let prefer-seat ( patches with [
        pcolor = color-available and any? neighbors with [pcolor = color-occupied and any? turtles-here with [ breed = group and status = status-playing ]]
    ])
      ifelse count prefer-seat > 0 ;  有可以社交的座位
      [go-to-toy  prefer-seat] ;  去那个座位
     [ let nntoy count available-toy
      if nntoy > 0 [;  玩具有空余
        go-to-toy  available-toy  ;向一个玩具去玩耍
    ]]
    ]
   [ let nntoy count available-toy
      if nntoy > 0 [;  玩具有空余
        go-to-toy  available-toy  ;向一个玩具去玩耍
]]]
    ask group with [status = status-goingsocial ] [ ;  状态 去社交
    let available-social-toy ( patches with [pcolor = color-occupied and any? turtles-here with [ breed = group and status = status-playing and social = false]])
    ;玩具没有空余，去社交
      let n-social-toy count available-social-toy
      if n-social-toy > 0 [;向一个玩具去社交
        go-to-toy  available-social-toy
      ]
     ]
end

to-report list-in [x y li]
  let xy list x y
  let bool member? xy li
  report bool
end

to to-wander [object group ]
  let status-wandering "wandering"
  if object = "photo" [
  set status-wandering "wandering-photo"
    ]
  if object = "exercise" [
  set status-wandering "wandering-exercise"
  ]
      if object = "rest" [
  set status-wandering "wandering-rest"
  ]
    ask group with [status = status-wandering ] [ ;  状态 游荡的
    set heading random 361
            go-forward
  ]
end


to go-to-toy [available-toy] ;;向一个玩具行动
      let mytoy min-one-of available-toy [dis [xcor] of myself [ycor] of myself pxcor  pycor ];  选离我最近的玩具
        let mytoy-xy [list pxcor pycor] of mytoy
        set velocity (map - mytoy-xy (list xcor ycor))
        set velocity normalize velocity; 速度 指向玩具
        facexy xcor + (first velocity) ycor + (last velocity) ; 定义行动方向
        setxy xcor + (first velocity) ycor + (last velocity); 行动
end


to to-link [group]
  ask group with [status = "playing-dinner"] [
    let me who
    let myneighbor group with [distance myself <= 2 and distance myself > 0 and not in-link-neighbor? myself and status = "playing-dinner"
    and who != me]
    if any? myneighbor [ ;如果不为空
    ask myneighbor [
      create-link-with myself
      if social = false [set social true]
        if not member? self list-workers-social [set list-workers-social lput self list-workers-social ]  ;加入社交列表
    ]
  ask my-links [set color gray - 2]
    ;set num-social-workers num-social-workers + count myneighbor
    set social true
      if not member? self list-workers-social [set list-workers-social lput self list-workers-social ]  ;加入社交列表
  ]]
  ask group with [status = "playing-rest"] [
     let myneighbor workers with [distance myself <= worker-radius and distance myself > 0 and not in-link-neighbor? myself and status = "playing-rest"  ]
  if any? myneighbor [ ;如果不为空
      ask myneighbor [
      create-link-with myself
      if social = false [set social true]
      if not member? self list-workers-social [set list-workers-social lput self list-workers-social ]  ;加入社交列表
    ]
   ask my-links [set color gray - 2]
   ; set num-social-workers num-social-workers + count myneighbor
    set social true
      if not member? self list-workers-social [set list-workers-social lput self list-workers-social ] ; 加入社交列表
  ]]
end


to to-die [group]
  if group = children [
  set list-time-children lput my-time list-time-children
  set list-satisfaction-children lput satisfaction list-satisfaction-children
    if my-time-toy > 0 [ set list-time-children-toy lput my-time-toy list-time-children-toy]
    if my-time-social > 0 [ set list-time-children-social lput my-time-social list-time-children-social]
    if my-time-photo > 0 [ set list-time-children-photo lput my-time-photo list-time-children-photo]
    ]
  if group = adults [
  set list-time-adults lput my-time list-time-adults
  set list-satisfaction-adults lput satisfaction list-satisfaction-adults
    if my-time-toy > 0 [ set list-time-adults-toy lput my-time-toy list-time-adults-toy]
    if my-time-social > 0 [ set list-time-adults-toy lput my-time-social list-time-adults-social]
    if my-time-photo > 0 [ set list-time-adults-toy lput my-time-photo list-time-adults-photo]
    if my-time-exercise  > 0 [ set list-time-adults-exercise lput my-time-exercise list-time-adults-exercise]
    if my-time-rest > 0 [ set list-time-adults-rest lput my-time-rest list-time-adults-rest]
    ]
  if group = elders [
  set list-time-elders lput my-time list-time-elders
  set list-satisfaction-elders lput satisfaction list-satisfaction-elders
    if my-time-social > 0 [ set list-time-elders-social lput my-time-social list-time-elders-social]
    if my-time-exercise  > 0 [ set list-time-elders-exercise lput my-time-exercise list-time-elders-exercise]
    if my-time-rest > 0 [ set list-time-elders-rest lput my-time-rest list-time-elders-rest]
    ]
  if group = workers [
  set list-time-workers lput my-time list-time-workers
  set list-satisfaction-workers lput satisfaction list-satisfaction-workers
    if my-time-social > 0 [ set list-time-workers-social lput my-time-social list-time-workers-social]
    if my-time-exercise  > 0 [ set list-time-workers-exercise lput my-time-exercise list-time-workers-exercise]
    if my-time-rest > 0 [ set list-time-workers-rest lput my-time-rest list-time-workers-rest]
    if my-time-dinner  > 0 [ set list-time-workers-dinner lput my-time-dinner list-time-workers-dinner]
    if my-time-photo > 0 [ set list-time-workers-photo lput my-time-rest list-time-workers-photo]
    ]
  die
end


to to-home [group] ;玩累的 回家
  ask group with [status = "goinghome"] [
    ifelse pcolor = black
    [ to-die group ]
    [go-forward]
  ]
end

to test-group [group]
  if group = children [ show "children"]
  if group = elders [ show "elders"]
  if group = workers [ show "workers"]
  if group = adults [ show "adults"]

end


to breed-us [group] ;新增儿童
  if group = "children" [
  if random 10000 < increase-children [
    create-my-children 1
      set num-agents num-agents + 1
  ]
  ]
  if group = "adults" [
  if random 10000 < increase-adults [
    create-my-adults 1
      set num-agents num-agents + 1
  ]
  ]
  if group = "elders" [
  if random 10000 < increase-elders [
    create-my-elders 1
      set num-agents num-agents + 1
  ]
  ]
  if group = "workers" [
  if random 10000 < increase-workers [
    create-my-workers 1
      set num-agents num-agents + 1
  ]
  ]
end

to go-forward
  forward 1.5
end

to add-time [group]
  ask group [
    if pcolor != black [set my-time my-time + 1]
  ]
end

to to-file ;输出到文件
  if  world-second mod  3600 = 0 [
    ;输出turtles
    ;children
   let filename word day  "day"
   set filename word filename hour
   set filename word filename "hour"
   set filename word filename minute
   set filename word filename "minute"
   set filename word filename "-tultles.txt"
   file-open filename
   file-print "tultles,my-time,my-time-exercise,my-time-toy,my-time-social,my-time-rest,my-time-photo,my-time-dinner,satisfaction"
   ask children
   [   file-type "children" file-write who file-type ","
      file-write my-time file-type ","
      file-write my-time-exercise file-type ","
      file-write my-time-toy file-type ","
      file-write my-time-social file-type ","
      file-write my-time-rest file-type ","
      file-write my-time-photo file-type ","
      file-write my-time-dinner file-type ","
     file-print satisfaction
   ]
       ;adults
   ask adults
   [  file-type "adults"  file-write who file-type ","
      file-write my-time file-type ","
      file-write my-time-exercise file-type ","
      file-write my-time-toy file-type ","
      file-write my-time-social file-type ","
      file-write my-time-rest file-type ","
      file-write my-time-photo file-type ","
      file-write my-time-dinner file-type ","
     file-print satisfaction
   ]
    ;elders
    ask elders
   [  file-type "elders" file-write who file-type ","
      file-write my-time file-type ","
      file-write my-time-exercise file-type ","
      file-write my-time-toy file-type ","
      file-write my-time-social file-type ","
      file-write my-time-rest file-type ","
      file-write my-time-photo file-type ","
      file-write my-time-dinner file-type ","
     file-print satisfaction
   ]
       ;workers
   ask workers
   [    file-type "workers" file-write who file-type ","
      file-write my-time file-type ","
      file-write my-time-exercise file-type ","
      file-write my-time-toy file-type ","
      file-write my-time-social file-type ","
      file-write my-time-rest file-type ","
      file-write my-time-photo file-type ","
      file-write my-time-dinner file-type ","
     file-print satisfaction
   ]
     ;输出统计数据
     set filename word day  "day"
   set filename word filename hour
   set filename word filename "hour"
   set filename word filename minute
   set filename word filename "minute"
   set filename word filename "-stats.txt"
   file-open filename
   ;使用设施的人数
    file-type "num-children-toy, "
    file-print length  list-children-toy
    file-type "num-children-social, "
    file-print length  list-children-social
    file-type "num-children-photo, "
    file-print length  list-children-photo

    file-type "num-adults-toy, "
    file-print length  list-adults-toy
    file-type "num-adults-social, "
    file-print length  list-adults-social
    file-type "num-adults-photo, "
    file-print length  list-adults-photo
    file-type "num-adults-rest, "
    file-print length  list-adults-rest
    file-type "num-adults-exercise, "
    file-print length  list-adults-exercise

    file-type "num-elders-social, "
    file-print length  list-elders-social
    file-type "num-elders-rest, "
    file-print length  list-elders-rest
    file-type "num-elders-exercise, "
    file-print length  list-elders-exercise

    file-type "num-workers-social, "
    file-print length  list-workers-social
    file-type "num-workers-rest, "
    file-print length  list-workers-rest
    file-type "num-workers-exercise, "
    file-print length  list-workers-exercise
    file-type "num-workers-dinner, "
    file-print length  list-workers-dinner
    file-type "num-workers-photo, "
    file-print length  list-workers-photo


    ;使用设施的频率
    file-type "num-use-toy, "
    file-print num-use-toy
    file-type "num-use-photo, "
    file-print num-use-photo
    file-type "num-use-exercise, "
    file-print num-use-exercise
    file-type "num-use-rest, "
    file-print num-use-rest
    file-type "num-use-dinner, "
    file-print num-use-dinner

    ;输出turtles位置
   file-print "tultles,xcor,ycor"
     set filename word day  "day"
   set filename word filename hour
   set filename word filename "hour"
   set filename word filename minute
   set filename word filename "minute"
   set filename word filename "-turtlesXY.txt"
   file-open filename
      ask children
   [   file-type "children" file-write who file-type ","
      file-write xcor + (33 / 2) file-type ","
      file-print ycor - (19 / 2)
   ]
      ask adults
   [   file-type "adults" file-write who file-type ","
      file-write xcor + (33 / 2) file-type ","
      file-print ycor - (19 / 2)
   ]
      ask elders
   [   file-type "elders" file-write who file-type ","
      file-write xcor + (33 / 2)file-type ","
      file-print ycor - (19 / 2)
   ]
      ask workers
   [   file-type "workers" file-write who file-type ","
      file-write xcor + (33 / 2) file-type ","
      file-print ycor - (19 / 2)
   ]

     file-close-all
  ]
end

to-report portion-toy-children
  let p 100 - portion-photo-children
 report p
end
to-report portion-toy-adults
  let p 100 - portion-photo-adults - portion-pass-adults - portion-exercise-adults - portion-rest-adults
 report p
end

to-report portion-rest-elders
    let p 100  - portion-exercise-elders
 report p
end
to-report portion-dinner-workers
    let p 100  - portion-exercise-workers - portion-photo-workers - portion-rest-workers
 report p
end

to-report day
  report int(world-second / (3600 * 24) )
end
to-report hour
  let a  world-second - day * 3600 * 24
  report int(a / 3600)
end
to-report minute
  let a  world-second - day * 3600 * 24 - hour * 3600
  report int(a / 60)
end
to-report second
  let a  world-second - day * 3600 * 24 - hour * 3600 - minute * 60
  report int(a mod 60)
end

to-report day-num-agents
  let p 0
  if  world-second mod (3600 * 24) = 0 [
  set p num-agents / day
  ]
  report p
end


to-report avg-time-object [object] ;各类活动平均停留时间
  let avg 0
  if object = "toy" ;游戏平均停留总时间
  [
  let sum-time 0
  if length list-time-children-toy > 0 [ set sum-time sum-time + reduce + list-time-children-toy]
  if length list-time-adults-toy > 0 [ set sum-time sum-time + reduce + list-time-adults-toy]
  let c length list-time-children-toy + length list-time-adults-toy
    if c > 0 [set avg sum-time / c]
  ]

  if object = "rest" ;休息平均停留总时间
  [
  let sum-time 0
  if length list-time-workers-rest > 0 [ set sum-time sum-time + reduce + list-time-workers-rest]
  if length list-time-adults-rest > 0 [ set sum-time sum-time + reduce + list-time-adults-rest]
  if length list-time-elders-rest > 0 [ set sum-time sum-time + reduce + list-time-elders-rest]
  let c length list-time-workers-rest + length list-time-adults-rest + length list-time-elders-rest
    if c > 0 [set avg sum-time / c]
  ]

  if object = "exercise" ;锻炼平均停留总时间
  [
  let sum-time 0
  if length list-time-workers-exercise > 0 [ set sum-time sum-time + reduce + list-time-workers-exercise]
  if length list-time-adults-exercise > 0 [ set sum-time sum-time + reduce + list-time-adults-exercise]
  if length list-time-elders-exercise > 0 [ set sum-time sum-time + reduce + list-time-elders-exercise]
  let c length list-time-workers-exercise + length list-time-adults-exercise + length list-time-elders-exercise
    if c > 0 [set avg sum-time / c]
  ]

  if object = "photo" ;拍照平均停留总时间
  [
  let sum-time 0
  if length list-time-workers-photo > 0 [ set sum-time sum-time + reduce + list-time-workers-photo]
  if length list-time-adults-photo > 0 [ set sum-time sum-time + reduce + list-time-adults-photo]
  if length list-time-children-photo > 0 [ set sum-time sum-time + reduce + list-time-children-photo]
  let c length list-time-workers-photo + length list-time-adults-photo + length list-time-children-photo
    if c > 0 [set avg sum-time / c]
  ]

  if object = "social" ;社交平均停留总时间
  [
  let sum-time 0
  if length list-time-workers-social > 0 [ set sum-time sum-time + reduce + list-time-workers-social]
  if length list-time-adults-social > 0 [ set sum-time sum-time + reduce + list-time-adults-social]
  if length list-time-children-social > 0 [ set sum-time sum-time + reduce + list-time-children-social]
  if length list-time-elders-social > 0 [ set sum-time sum-time + reduce + list-time-elders-social]
  let c length list-time-workers-social + length list-time-adults-social + length list-time-children-social + length list-time-elders-social
    if c > 0 [set avg sum-time / c]
  ]

  if object = "dinner" ;吃饭平均停留总时间
  [
  let sum-time 0
  if length list-time-workers-dinner > 0 [ set sum-time sum-time + reduce + list-time-workers-dinner]
  let c length list-time-workers-dinner
    if c > 0 [ set avg sum-time / c]
  ]

  report avg
end


to-report avg-time [group object] ;平均停留时间/满意度
  let avg 0

  if object = "all" [ ;平均停留总时间
  let sum-time 0
  if length list-time-children > 0 [ set sum-time sum-time + reduce + list-time-children]
  if length list-time-adults > 0 [ set sum-time sum-time + reduce + list-time-adults]
  if length list-time-elders > 0 [ set sum-time sum-time + reduce + list-time-elders]
  if length list-time-workers > 0 [ set sum-time sum-time + reduce + list-time-workers]
  let c length list-time-children + length list-time-adults + length list-time-elders + length list-time-workers
    if c > 0 [set avg sum-time / c]]

  if object = "breed" [ ;平均停留总时间 种群
    if group = "children" [
    let sum-time 0
  if length list-time-children > 0 [
        set sum-time sum-time + reduce + list-time-children
      set avg sum-time / length list-time-children]
    ]
    if group = "adults" [
    let sum-time 0
  if length list-time-adults > 0 [
        set sum-time sum-time + reduce + list-time-adults
      set avg sum-time / length list-time-adults]
    ]
    if group = "elders" [
    let sum-time 0
  if length list-time-elders > 0 [
        set sum-time sum-time + reduce + list-time-elders
      set avg sum-time / length list-time-elders]
    ]
    if group = "workers" [
    let sum-time 0
  if length list-time-workers > 0 [
        set sum-time sum-time + reduce + list-time-workers
      set avg sum-time / length list-time-workers]
    ]
   ]

  if object = "satisfaction" [ ;各类群体的满意度
    if group = "children" [
    let sum-time 0
       set avg 0
  if length list-satisfaction-children > 0 [
        set sum-time sum-time + reduce + list-satisfaction-children
      set avg sum-time / length list-satisfaction-children ]    ]

    if group = "adults" [
    let sum-time 0
  if length list-satisfaction-adults > 0 [
        set sum-time sum-time + reduce + list-satisfaction-adults
      set avg sum-time / length list-satisfaction-adults ]    ]

    if group = "elders" [
    let sum-time 0
  if length list-satisfaction-elders > 0 [
        set sum-time sum-time + reduce + list-satisfaction-elders
      set avg sum-time / length list-satisfaction-elders ]    ]

    if group = "workers" [
    let sum-time 0
  if length list-satisfaction-workers > 0 [
        set sum-time sum-time + reduce + list-satisfaction-workers
      set avg sum-time / length list-satisfaction-workers ]    ]
  ]


  if object = "toy" [ ;玩具
    if group = "children" [
    let sum-time 0
  if length list-time-children-toy > 0 [
        set sum-time sum-time + reduce + list-time-children-toy
      set avg sum-time / length list-time-children-toy ]    ]

    if group = "adults" [
    let sum-time 0
  if length list-time-adults-toy > 0 [
        set sum-time sum-time + reduce + list-time-adults-toy
      set avg sum-time / length list-time-adults-toy ]    ]
  ]


  if object = "exercise" [ ;锻炼
    if group = "adults" [
    let sum-time 0
  if length list-time-adults-exercise > 0 [
        set sum-time sum-time + reduce + list-time-adults-exercise
      set avg sum-time / length list-time-adults-exercise]    ]
    if group = "workers" [
    let sum-time 0
  if length list-time-workers-exercise > 0 [
        set sum-time sum-time + reduce + list-time-workers-exercise
      set avg sum-time / length list-time-workers-exercise]    ]
    if group = "elders" [
    let sum-time 0
  if length list-time-elders-exercise > 0 [
        set sum-time sum-time + reduce + list-time-elders-exercise
      set avg sum-time / length list-time-elders-exercise]    ]
  ]
  if object = "social" [ ;社交
    if group = "adults" [
    let sum-time 0
  if length list-time-adults-social > 0 [
        set sum-time sum-time + reduce + list-time-adults-social
      set avg sum-time / length list-time-adults-social]    ]
    if group = "workers" [
    let sum-time 0
  if length list-time-workers-social > 0 [
        set sum-time sum-time + reduce + list-time-workers-social
      set avg sum-time / length list-time-workers-social]    ]
    if group = "elders" [
    let sum-time 0
  if length list-time-elders-social > 0 [
        set sum-time sum-time + reduce + list-time-elders-social
      set avg sum-time / length list-time-elders-social]    ]
    if group = "children" [
    let sum-time 0
  if length list-time-children-social > 0 [
        set sum-time sum-time + reduce + list-time-children-social
      set avg sum-time / length list-time-children-social]    ]
  ]
  if object = "rest" [ ;休息
    if group = "adults" [
    let sum-time 0
  if length list-time-adults-rest > 0 [
        set sum-time sum-time + reduce + list-time-adults-rest
      set avg sum-time / length list-time-adults-rest]    ]
    if group = "workers" [
    let sum-time 0
  if length list-time-workers-rest > 0 [
        set sum-time sum-time + reduce + list-time-workers-rest
      set avg sum-time / length list-time-workers-rest]    ]
    if group = "elders" [
    let sum-time 0
  if length list-time-elders-rest > 0 [
        set sum-time sum-time + reduce + list-time-elders-rest
      set avg sum-time / length list-time-elders-rest]    ]
  ]
  if object = "dinner" [ ;吃饭
    if group = "workers" [
    let sum-time 0
  if length list-time-workers-dinner > 0 [
        set sum-time sum-time + reduce + list-time-workers-dinner
      set avg sum-time / length list-time-workers-dinner]    ]
  ]
  if object = "photo" [ ;拍照
    if group = "adults" [
    let sum-time 0
  if length list-time-adults-photo > 0 [
        set sum-time sum-time + reduce + list-time-adults-photo
      set avg sum-time / length list-time-adults-photo]    ]
    if group = "workers" [
    let sum-time 0
  if length list-time-workers-photo > 0 [
        set sum-time sum-time + reduce + list-time-workers-photo
      set avg sum-time / length list-time-workers-photo]    ]
    if group = "elders" [
    let sum-time 0
  if length list-time-children-photo > 0 [
        set sum-time sum-time + reduce + list-time-children-photo
      set avg sum-time / length list-time-children-photo]    ]
  ]
 report avg
end

to-report num-agentset [li]
  ;let li1 filter [ i -> i != nobody ] li
  let n 0
  if length li > 0 [set n length li ]
  report n
end

to-report ntoy
  ;let available-toy patches with [pcolor = red]
  ;let mytoy one-of available-toy
  let numtoy  [list pxcor pycor] of thistoy
  report numtoy
end

to-report dis [x1 y1 x2 y2]
  let thisdis   sqrt( (x1 - x2) *  (x1 - x2) + (y1 - y2) * (y1 - y2))
  report thisdis
end

to-report normalize [xy]
  let realdis norm xy
  let out [0 0]
  if realdis > 0 [
    set out (map [ ?1 -> ?1 / realdis] xy)
  ]
  report out

end

to-report norm [arr]
  let xx first arr
  let yy last arr
  report sqrt (xx * xx + yy * yy)

end

to-report list2contain1 [li1 li2] ; 2是否包含1的每个元素
  let boo true
  foreach li1 [x -> set boo boo and member? x li2]
  report boo
end
@#$#@#$#@
GRAPHICS-WINDOW
0
487
968
1049
-1
-1
29.11
1
10
1
1
1
0
1
1
1
-16
16
-9
9
1
1
1
ticks
30.0

BUTTON
722
360
795
393
setup
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1

BUTTON
647
360
710
393
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1

SLIDER
225
53
397
86
num-children
num-children
0
10
0.0
1
1
NIL
HORIZONTAL

SLIDER
223
272
395
305
energy-children
energy-children
5
2000
1196.0
1
1
NIL
HORIZONTAL

SLIDER
226
105
398
138
increase-children
increase-children
0
100
3.0
1
1
NIL
HORIZONTAL

BUTTON
184
433
264
466
go once
go
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1

PLOT
24
1061
391
1399
children num played
time
num-children
0.0
10.0
0.0
60.0
true
true
"" ""
PENS
"toy" 1.0 0 -2064490 true "" "plot  num-agentset list-children-toy"
"social" 1.0 0 -5825686 true "" "plot  num-agentset list-children-social"
"social-time" 1.0 0 -12186836 true "" "plot  avg-time \"children\" \"social\" / 60"

SLIDER
226
158
399
191
portion-photo-children
portion-photo-children
0
100
0.0
1
1
NIL
HORIZONTAL

SLIDER
424
52
596
85
num-adults
num-adults
0
10
0.0
1
1
NIL
HORIZONTAL

SLIDER
424
95
596
128
increase-adults
increase-adults
0
200
17.0
1
1
NIL
HORIZONTAL

SLIDER
423
137
611
170
portion-photo-adults
portion-photo-adults
0
100
0.0
1
1
NIL
HORIZONTAL

SLIDER
423
181
604
214
portion-pass-adults
portion-pass-adults
0
100
50.0
1
1
NIL
HORIZONTAL

SLIDER
421
349
623
382
energy-adults
energy-adults
5
2000
800.0
1
1
NIL
HORIZONTAL

SLIDER
423
222
632
255
portion-exercise-adults
portion-exercise-adults
0
100
50.0
1
1
NIL
HORIZONTAL

MONITOR
233
210
384
255
NIL
portion-toy-children
17
1
11

MONITOR
425
300
563
345
NIL
portion-toy-adults
17
1
11

SLIDER
660
52
832
85
num-elders
num-elders
0
10
0.0
1
1
NIL
HORIZONTAL

SLIDER
660
99
832
132
increase-elders
increase-elders
0
100
23.0
1
1
NIL
HORIZONTAL

SLIDER
665
148
874
181
portion-exercise-elders
portion-exercise-elders
0
100
100.0
1
1
NIL
HORIZONTAL

MONITOR
667
201
811
246
NIL
portion-rest-elders
17
1
11

SLIDER
666
258
838
291
energy-elders
energy-elders
5
2000
706.0
1
1
NIL
HORIZONTAL

SLIDER
422
259
603
292
portion-rest-adults
portion-rest-adults
0
100
0.0
1
1
NIL
HORIZONTAL

SLIDER
26
52
198
85
energy-toy
energy-toy
0
1000
490.0
1
1
NIL
HORIZONTAL

SLIDER
28
110
200
143
energy-exercise
energy-exercise
0
1000
497.0
1
1
NIL
HORIZONTAL

SLIDER
29
164
201
197
time-photo
time-photo
0
1000
465.0
1
1
NIL
HORIZONTAL

SLIDER
28
220
200
253
time-rest
time-rest
0
1000
783.0
1
1
NIL
HORIZONTAL

SLIDER
908
49
1080
82
num-workers
num-workers
0
20
0.0
1
1
NIL
HORIZONTAL

SLIDER
909
99
1081
132
increase-workers
increase-workers
0
100
6.0
1
1
NIL
HORIZONTAL

SLIDER
908
150
1124
183
portion-exercise-workers
portion-exercise-workers
0
100
0.0
1
1
NIL
HORIZONTAL

SLIDER
910
199
1098
232
portion-rest-workers
portion-rest-workers
0
100
0.0
1
1
NIL
HORIZONTAL

SLIDER
909
247
1104
280
portion-photo-workers
portion-photo-workers
0
100
0.0
1
1
NIL
HORIZONTAL

MONITOR
910
292
1075
337
portion-dinner-workers
portion-dinner-workers
17
1
11

SLIDER
909
347
1081
380
energy-workers
energy-workers
0
2000
700.0
1
1
NIL
HORIZONTAL

SLIDER
30
270
202
303
time-dinner
time-dinner
0
1000
764.0
1
1
NIL
HORIZONTAL

CHOOSER
32
363
170
408
playground
playground
"current" "future"
1

MONITOR
370
426
427
471
NIL
hour
17
1
11

MONITOR
440
425
497
470
NIL
minute
17
1
11

MONITOR
513
426
570
471
NIL
second
17
1
11

MONITOR
302
425
359
470
NIL
day
17
1
11

MONITOR
645
425
734
470
日均到访人数
day-num-agents
2
1
11

MONITOR
1336
428
1425
473
平均停留时间
avg-time children \"all\"
2
1
11

MONITOR
1126
371
1215
416
玩具使用次数
num-use-toy
17
1
11

MONITOR
1122
211
1208
256
打卡设施使用次数
num-use-photo
17
1
11

MONITOR
1125
319
1217
364
休息座位使用次数
num-use-rest
17
1
11

MONITOR
1124
265
1215
310
健身器材使用次数
num-use-exercise
17
1
11

MONITOR
1127
424
1217
469
餐桌椅使用次数
num-use-dinner
17
1
11

PLOT
416
1067
823
1399
ground num played
time
num
0.0
3600.0
0.0
120.0
true
true
"" ""
PENS
"num-use-toy" 1.0 0 -2064490 true "" "plot num-use-toy"
"num-use-photo" 1.0 0 -13345367 true "" "plot num-use-photo"
"num-use-exercise" 1.0 0 -7858858 true "" "plot num-use-exercise"
"num-use-rest" 1.0 0 -13791810 true "" "plot num-use-rest"
"num-use-dinner" 1.0 0 -11221820 true "" "plot num-use-dinner"

PLOT
24
1406
372
1578
adults num played
NIL
NIL
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
"toy" 1.0 0 -2674135 true "" "plot num-agentset list-adults-toy"
"social" 1.0 0 -7500403 true "" "plot num-agentset list-adults-social"
"rest" 1.0 0 -11221820 true "" "plot num-agentset list-adults-rest"
"photo" 1.0 0 -13345367 true "" "plot num-agentset list-adults-photo"
"adults-exercise" 1.0 0 -11881837 true "" "plot num-agentset list-adults-exercise"

PLOT
842
1069
1216
1395
num-activity
time
num
0.0
3600.0
0.0
100.0
true
true
"" ""
PENS
"num-exercise" 1.0 0 -5825686 true "" "plot num-agentset list-exercise"
"num-toy" 1.0 0 -2064490 true "" "plot num-agentset list-toy"
"num-rest" 1.0 0 -13791810 true "" "plot num-agentset list-rest"
"num-photo" 1.0 0 -13345367 true "" "plot num-agentset list-photo"
"num-dinner" 1.0 0 -11221820 true "" "plot num-agentset list-dinner"
"num-social" 1.0 0 -12186836 true "" "plot num-agentset list-social"
"num-all" 1.0 0 -16777216 true "" "plot num-agentset list-exercise + num-agentset list-social + num-agentset list-dinner + num-agentset list-photo + num-agentset list-toy + num-agentset list-rest"

PLOT
1463
499
1934
869
activity time
time
activity time
0.0
30000.0
0.0
25.0
true
true
"" ""
PENS
"exercise-time" 1.0 0 -5825686 true "" "plot avg-time-object \"exercise\" / 60"
"toy-time" 1.0 0 -2064490 true "" "plot avg-time-object \"toy\" / 60"
"rest-time" 1.0 0 -13791810 true "" "plot avg-time-object \"rest\" / 60"
"photo-time" 1.0 0 -13345367 true "" "plot avg-time-object \"photo\" / 60"
"dinner-time" 1.0 0 -11221820 true "" "plot avg-time-object \"dinner\" / 60"
"social-time" 1.0 0 -10603201 true "" "plot avg-time-object \"social\" / 60"

PLOT
980
487
1450
798
group-satisfaction
time
satisfaction
0.0
10.0
-300.0
1500.0
true
true
"" ""
PENS
"children" 1.0 0 -2064490 true "" "plot avg-time \"children\" \"satisfaction\""
"adults" 1.0 0 -13345367 true "" "plot avg-time \"adults\" \"satisfaction\""
"elders" 1.0 0 -11221820 true "" "plot avg-time \"elders\" \"satisfaction\""
"workers" 1.0 0 -5825686 true "" "plot avg-time \"workers\" \"satisfaction\""

MONITOR
1230
211
1319
256
平均锻炼时间
avg-time-object \"exercise\" / 60
1
1
11

MONITOR
1231
265
1320
310
平均游戏时间
avg-time-object \"toy\" / 60
1
1
11

MONITOR
1231
321
1320
366
平均休息时间
avg-time-object \"rest\" / 60
1
1
11

MONITOR
1231
375
1320
420
平均吃饭时间
avg-time-object \"dinner\" / 60
1
1
11

MONITOR
1233
426
1322
471
平均社交时间
avg-time-object \"social\" / 60
1
1
11

MONITOR
1335
211
1412
256
儿童满意度
avg-time \"children\" \"satisfaction\"
1
1
11

MONITOR
1334
263
1436
308
中青年人满意度
avg-time \"adults\" \"satisfaction\"
1
1
11

MONITOR
1334
318
1423
363
老年人满意度
avg-time \"elders\" \"satisfaction\"
1
1
11

MONITOR
1333
373
1454
418
工人/外卖员满意度
avg-time \"workers\" \"satisfaction\"
1
1
11

MONITOR
1336
154
1425
199
儿童社交人数
num-agentset list-children-social
1
1
11

MONITOR
1337
101
1426
146
儿童社交时间
avg-time \"children\" \"social\" / 60
1
1
11

MONITOR
1337
51
1426
96
儿童游戏人数
num-agentset list-children-toy
1
1
11

SWITCH
37
436
140
469
preset
preset
0
1
-1000

@#$#@#$#@
## WHAT IS IT?

(a general understanding of what the model is trying to show or explain)

## HOW IT WORKS

(what rules the agents use to create the overall behavior of the model)

## HOW TO USE IT

(how to use the model, including a description of each of the items in the Interface tab)

## THINGS TO NOTICE

(suggested things for the user to notice while running the model)

## THINGS TO TRY

(suggested things for the user to try to do (move sliders, switches, etc.) with the model)

## EXTENDING THE MODEL

(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)

## NETLOGO FEATURES

(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)

## RELATED MODELS

(models in the NetLogo Models Library and elsewhere which are of related interest)

## CREDITS AND REFERENCES

(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
@#$#@#$#@
default
true
0
Polygon -7500403 true true 150 5 40 250 150 205 260 250

airplane
true
0
Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15

arrow
true
0
Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150

box
false
0
Polygon -7500403 true true 150 285 285 225 285 75 150 135
Polygon -7500403 true true 150 135 15 75 150 15 285 75
Polygon -7500403 true true 15 75 15 225 150 285 150 135
Line -16777216 false 150 285 150 135
Line -16777216 false 150 135 15 75
Line -16777216 false 150 135 285 75

bug
true
0
Circle -7500403 true true 96 182 108
Circle -7500403 true true 110 127 80
Circle -7500403 true true 110 75 80
Line -7500403 true 150 100 80 30
Line -7500403 true 150 100 220 30

butterfly
true
0
Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240
Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240
Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163
Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165
Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225
Circle -16777216 true false 135 90 30
Line -16777216 false 150 105 195 60
Line -16777216 false 150 105 105 60

car
false
0
Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180
Circle -16777216 true false 180 180 90
Circle -16777216 true false 30 180 90
Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89
Circle -7500403 true true 47 195 58
Circle -7500403 true true 195 195 58

circle
false
0
Circle -7500403 true true 0 0 300

circle 2
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240

cow
false
0
Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167
Polygon -7500403 true true 73 210 86 251 62 249 48 208
Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123

cylinder
false
0
Circle -7500403 true true 0 0 300

dot
false
0
Circle -7500403 true true 90 90 120

face happy
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240

face neutral
false
0
Circle -7500403 true true 8 7 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Rectangle -16777216 true false 60 195 240 225

face sad
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183

fish
false
0
Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166
Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165
Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60
Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166
Circle -16777216 true false 215 106 30

flag
false
0
Rectangle -7500403 true true 60 15 75 300
Polygon -7500403 true true 90 150 270 90 90 30
Line -7500403 true 75 135 90 135
Line -7500403 true 75 45 90 45

flower
false
0
Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135
Circle -7500403 true true 85 132 38
Circle -7500403 true true 130 147 38
Circle -7500403 true true 192 85 38
Circle -7500403 true true 85 40 38
Circle -7500403 true true 177 40 38
Circle -7500403 true true 177 132 38
Circle -7500403 true true 70 85 38
Circle -7500403 true true 130 25 38
Circle -7500403 true true 96 51 108
Circle -16777216 true false 113 68 74
Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218
Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240

house
false
0
Rectangle -7500403 true true 45 120 255 285
Rectangle -16777216 true false 120 210 180 285
Polygon -7500403 true true 15 120 150 15 285 120
Line -16777216 false 30 120 270 120

leaf
false
0
Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195
Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195

line
true
0
Line -7500403 true 150 0 150 300

line half
true
0
Line -7500403 true 150 0 150 150

pentagon
false
0
Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120

person
false
0
Circle -7500403 true true 110 5 80
Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90
Rectangle -7500403 true true 127 79 172 94
Polygon -7500403 true true 195 90 240 150 225 180 165 105
Polygon -7500403 true true 105 90 60 150 75 180 135 105

plant
false
0
Rectangle -7500403 true true 135 90 165 300
Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285
Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285
Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210
Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135
Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135
Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60
Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90

sheep
false
15
Circle -1 true true 203 65 88
Circle -1 true true 70 65 162
Circle -1 true true 150 105 120
Polygon -7500403 true false 218 120 240 165 255 165 278 120
Circle -7500403 true false 214 72 67
Rectangle -1 true true 164 223 179 298
Polygon -1 true true 45 285 30 285 30 240 15 195 45 210
Circle -1 true true 3 83 150
Rectangle -1 true true 65 221 80 296
Polygon -1 true true 195 285 210 285 210 240 240 210 195 210
Polygon -7500403 true false 276 85 285 105 302 99 294 83
Polygon -7500403 true false 219 85 210 105 193 99 201 83

square
false
0
Rectangle -7500403 true true 30 30 270 270

square 2
false
0
Rectangle -7500403 true true 30 30 270 270
Rectangle -16777216 true false 60 60 240 240

star
false
0
Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108

target
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240
Circle -7500403 true true 60 60 180
Circle -16777216 true false 90 90 120
Circle -7500403 true true 120 120 60

tree
false
0
Circle -7500403 true true 118 3 94
Rectangle -6459832 true false 120 195 180 300
Circle -7500403 true true 65 21 108
Circle -7500403 true true 116 41 127
Circle -7500403 true true 45 90 120
Circle -7500403 true true 104 74 152

triangle
false
0
Polygon -7500403 true true 150 30 15 255 285 255

triangle 2
false
0
Polygon -7500403 true true 150 30 15 255 285 255
Polygon -16777216 true false 151 99 225 223 75 224

truck
false
0
Rectangle -7500403 true true 4 45 195 187
Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194
Rectangle -1 true false 195 60 195 105
Polygon -16777216 true false 238 112 252 141 219 141 218 112
Circle -16777216 true false 234 174 42
Rectangle -7500403 true true 181 185 214 194
Circle -16777216 true false 144 174 42
Circle -16777216 true false 24 174 42
Circle -7500403 false true 24 174 42
Circle -7500403 false true 144 174 42
Circle -7500403 false true 234 174 42

turtle
true
0
Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210
Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105
Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105
Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87
Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210
Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99

wheel
false
0
Circle -7500403 true true 3 3 294
Circle -16777216 true false 30 30 240
Line -7500403 true 150 285 150 15
Line -7500403 true 15 150 285 150
Circle -7500403 true true 120 120 60
Line -7500403 true 216 40 79 269
Line -7500403 true 40 84 269 221
Line -7500403 true 40 216 269 79
Line -7500403 true 84 40 221 269

wolf
false
0
Polygon -16777216 true false 253 133 245 131 245 133
Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105
Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113

x
false
0
Polygon -7500403 true true 270 75 225 30 30 225 75 270
Polygon -7500403 true true 30 75 75 30 270 225 225 270
@#$#@#$#@
NetLogo 6.1.1
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
default
0.0
-0.2 0 0.0 1.0
0.0 1 1.0 0.0
0.2 0 0.0 1.0
link direction
true
0
Line -7500403 true 150 150 90 180
Line -7500403 true 150 150 210 180
@#$#@#$#@
0
@#$#@#$#@
